cmake_minimum_required(VERSION 3.10)


project(VideoBlur LANGUAGES CXX)


set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})

include_directories(${PROJECT_SOURCE_DIR}/../include)

# 收集所有 .cpp 文件
file(GLOB SOURCE_FILES "*.cpp")
# 确保 main.cpp 和 hdmi-rx_monitor.cpp 不参与 video_blur 构建
list(REMOVE_ITEM SOURCE_FILES "main.cpp")


# 构建主程序 video_blur
add_executable(video_blur main.cpp ${SOURCE_FILES})
target_link_libraries(video_blur PRIVATE
    ${SDL2_LIBRARIES}
    ${GLEW_LIBRARIES}
    avcodec
    avformat
    avutil
    avdevice
    swscale
    rga
    pthread
    udev
    m
    GL
)

if(NOT DEFINED CMAKE_INSTALL_PREFIX)
    set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE)
endif()

# ========== 可执行程序安装到 /usr/local/bin ==========
install(TARGETS video_blur DESTINATION bin)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/../build/rockchip/monitor/hdmi-rx_monitor DESTINATION bin)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/../build/rockchip/hdmi_insert.sh DESTINATION bin)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/../build/rockchip/hdmi_remove.sh DESTINATION bin)
        


        
# ========== 桌面文件安装到 ~/.config/autostart ==========
set(USER_AUTOSTART_DIR "$ENV{HOME}/.config/autostart")
file(MAKE_DIRECTORY ${USER_AUTOSTART_DIR})

install(FILES ${PROJECT_SOURCE_DIR}/../build/rockchip/open-terminal.desktop
        DESTINATION ${USER_AUTOSTART_DIR}
        RENAME open-terminal.desktop)

# ========== 提示信息 ==========
message(STATUS "Installing video_blur to: ${CMAKE_INSTALL_PREFIX}/bin/video_blur")
message(STATUS "Installing hdmi-rx_monitor to: ${CMAKE_INSTALL_PREFIX}/bin/hdmi-rx_monitor")
message(STATUS "Installing hdmi_insert.sh to: ${CMAKE_INSTALL_PREFIX}/bin/hdmi_insert.sh")
message(STATUS "Installing open-terminal.desktop to: ~/.config/autostart/open-terminal.desktop")